#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
char* my_strncpy(char* str1, const char* str2, size_t n)
{
	assert(str1 && str2);
	char* p = str1;
	while (n--)
	{
		
		if (*str2 == '\0')
		{
			*str1= '\0';
			str1++;
		}
		else
		{ 
			*str1 = *str2;
			str1++, str2++;
		}
	}
	return p;
}
char* my_strncat(char* str1, const char* str2, size_t n)
{
	assert(str1 && str2);
	char* p = str1;
	while (str1++, *str1 != '\0');
	while (n--)
	{
		if (*str2 == '\0')
		{
			*str1=*str2;
			return p;
		}
		else
		{
			*str1 = *str2;
			str2++,str1++;
		}
		if (n == 0)
			*str1 = '\0';
	}
	return p;
}
void* my_memcpy(void* p1, const void* p2, size_t n)
{
	assert(p1 && p2);
	void* p=p1;
	while (n--)
	{
		*(char*)p1 = *(char*)p2;
		((char*)p1)++, ((char*)p2)++;
	}
	return p;
}
void* my_memmove(void* p1, void* p2, size_t n)
{
	void* p = p1;
	if (p1 > p2)
	{
		while (n--)
		{
			*(char*)p1 = *(char*)p2;
			((char*)p1)++, ((char*)p2)++;
		}
	}
	else
	{
		while (n--)
		{
			*((char*)p1 + n) = *((char*)p2 + n);
		}
	}
}
int main()
{
	//char a[20] = "jvsvk\0jb";
	//char b[] = "12568";
	int k[] = { 1,2,3,4,5 };
	int c[5] = { 10,20,30,40,50};
	//my_strncpy(a+3, b, 3);
	//my_strncat(a + 2, b, 3);
	//my_memcpy(c, k, sizeof(c[0])*3);
	my_memmove(c, c + 2, sizeof(c[0]) * 2);
	for (int i = 0; i < 5; i++)
	{
		printf("%d ", c[i]);
	}
	printf("\n");
	my_memmove(c + 3, c, sizeof(c[0]) * 2);
	for (int i = 0; i < 5; i++)
	{
		printf("%d ", c[i]);
	}
	return 0;
}

